//
//  JXHomeViewController.m
//  JXAddressApp
//
//  Created by huawei.zheng on 2018/10/27.
//  Copyright © 2018 zhhw_home. All rights reserved.
//

#import "JXHomeMapViewController.h"
#import "TMapView.h"
#import <CoreLocation/CoreLocation.h>

@interface JXHomeMapViewController ()
<TMapViewDelegate>

@property (nonatomic, strong) TMapView  *mapView;
@property (nonatomic, strong) CLLocationManager *locationManager;

@end

@implementation JXHomeMapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _locationManager = [[CLLocationManager alloc] init];
    [_locationManager requestWhenInUseAuthorization];
    [_locationManager startUpdatingLocation];
    
    _mapView = [[TMapView alloc]initWithFrame:self.view.frame];
    // 设置地图回调类
    _mapView.delegate = self;
    [self.view addSubview:_mapView];
    
    // 显示用户位置
    _mapView.ShowPosition = YES;
    // 当前跟踪模式,跟踪状态
    _mapView.UserTrackMode = TUserTrackingModeFollow;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];

    if (_mapView.UserTrackMode == TUserTrackingModeFollow) {
        [_mapView StartGetPosition];
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [_mapView StopGetPosition];
}

- (void)mapViewWillStartLocatingUser:(TMapView *)mapView
{
    NSLog(@"开始定位");
}

- (void)mapView:(TMapView *)mapView didChangeUserTrackingMode:(TUserTrackingMode)mode animated:(BOOL)animated {
    switch (mode) {
        case TUserTrackingModeNone:
            self.navigationItem.rightBarButtonItem.title = @"未定位";
            break;
        case TUserTrackingModeFollow:
            self.navigationItem.rightBarButtonItem.title = @"定位";
            break;
        default:
            break;
    }
}

@end
